<extend name="Public/base"/>

<block name="body">
    <div class="main-title">
        <h2>{$_title}</h2>
    </div>
    <form action="{:U('AppTest/apiTest')}" method="post" class="form-horizontal">
    	<div class="form-item">
            <label class="item-label">测试接口：<span class="check-tips">{$param.code|default=''}</span></label>
        </div>
        <div class="form-item">
            <label class="item-label">接口名称：<span class="check-tips">{$param.name|default=''}</span></label>
        </div>
    	<div class="form-item">
            <label class="item-label">请求方式：<span class="check-tips">{$param.method_text|default=''}</span></label>
             <input type="hidden" name="method" value="{$param.method|default=''}"/>
        </div>
        <div class="form-item">
            <label class="item-label">请求参数模板<span class="check-tips">（JSON格式字符串，仅用于后台测试接口）</span></label>
            <div class="controls">
                <textarea readonly style="width:890px;height:280px;padding:5px;" class="input-large">{$param.params_json|default=''}</textarea>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">待签名字符串<span class="check-tips">（仅用于后台测试接口）</span></label>
            <div class="controls">
                <textarea style="width:890px;height:280px;padding:5px;" class="input-large" name="param" id="sign_str"></textarea>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">请求参数<span class="check-tips">（JSON格式字符串，可点击生成参数按钮生成请求参数，仅用于后台测试接口）</span></label>
            <div class="controls">
                <textarea style="width:890px;height:280px;padding:5px;" class="input-large" name="param" id="param">{$param.params_json|default=''}</textarea>
            </div>
        </div>
        <div class="form-item">
            <button class="btn btn-return" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return ajax-post" id="c_json_param">生成参数</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</block>

<block name="script">
	<link rel="stylesheet" href="__PUBLIC__/static/kindeditor/default/default.css" />
	<script charset="utf-8" src="__PUBLIC__/static/kindeditor/kindeditor-min.js"></script>
	<script charset="utf-8" src="__PUBLIC__/static/kindeditor/zh_CN.js"></script>
    <script type="text/javascript">
		KindEditor.ready(function(K) {
			window.editor = K.create('textarea[class="kind-editor"]', {
				//allowFileManager : false
				minWidth:900,
				minHeight:300,
				afterBlur: function(){this.sync();},
			});
		});
	
		//生成参数按钮注册事件
		$("#c_json_param").click(function(){
			var param = $("#param").val();
			if(!param) {
				updateAlert('参数不能为空', 'alert-error');
				return;
			}
			ajaxRequest('{:U("AppTest/paramJson")}', {'param':param}, {'func':function(data){
				if(data) {
					if(data.error != 1) {
						$("#param").val(data.msg.param);
						$("#sign_str").val(data.msg.signStr);
						updateAlert('参数生成成功','alert-success');
					} else {
						updateAlert(data.msg, 'alert-error');
					}
				} else {
					updateAlert('请求失败', 'alert-error');
				}
				
				setTimeout(function(){
					$(".close").click();
				}, 1500);
			}});
		});
		
        //导航高亮
        highlight_subnav('{:U('Api/apiList')}');
    </script>
</block>
